package com.heima.crm.controller;


import com.heima.crm.common.result.PageResult;
import com.heima.crm.common.result.Result;
import com.heima.crm.pojos.dtos.DicTypePageDTO;
import com.heima.crm.pojos.entity.SysDictType;
import com.heima.crm.service.SysDicTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RequestMapping("/dic")
@RestController
public class SysDicTypeController {

    @Autowired
    private SysDicTypeService sysDicTypeService;

    //字典所有名称
    @GetMapping
    public Result allDictName(){
        return sysDicTypeService.allDictName();
    }

    //分页查询字典(名称,类型,状态,创建时间)
    @PostMapping("/list")
    public Result findList(@RequestBody DicTypePageDTO dto){
        return sysDicTypeService.findList(dto);
    }

    @PostMapping("/add")
    public Result add(@RequestBody SysDictType sysDictType){
        return sysDicTypeService.add(sysDictType);
    }

    @GetMapping("/findOne/{dicId}")
    public Result findById(@PathVariable Long dicId){
        return sysDicTypeService.findById(dicId);
    }

    @PutMapping("/update")
    public Result update(@RequestBody SysDictType sysDictType){
        return sysDicTypeService.update(sysDictType);
    }

    @DeleteMapping("/delete/{dicId}")
    public Result deleteById(@PathVariable Long dicId){
        return sysDicTypeService.deleteById(dicId);
    }

    @DeleteMapping("deleteIds")
    public Result deleteByIds(@RequestParam List<Long> ids){
        return sysDicTypeService.deleteByIds(ids);
    }


    @PostMapping("/export")
    public Result export(HttpServletResponse response,@RequestParam List<Long> ids){
        return sysDicTypeService.export(response,ids);
    }

}
